% this script concatenates the help documentation for all the .m files in this
% directory and its subdirectory

% get paths to all .m files in this directory or subdirectories (1-level deep)
[s,r] = system('find . -name "*.m" -depth 2');
% split on newline
files = regexp(r,'\n','split');
% get rid of empty paths (usually just a few at the end)
files = files(~cellfun(@isempty,files));
% get help documentation for each file
helps = cellfun(@help,files,'UniformOutput',false);
% concatenate files and helps
filesandhelps = cat(1,files,helps);
% write output to the screen
% output_handle = 1;
% write output to a file
output_handle = fopen('Documentation.txt','w');
% print list of files
fprintf(output_handle,'LIST OF FILES\n');
fprintf(output_handle,'  %s\n',files{:});
% print file paths and helps 
fprintf(output_handle,'\n\nHELP DOCUMENTATION FOR EACH FILE\n');
fprintf(output_handle,'%s\n%s\n\n',fh{:});
fprintf(output_handle,'\n\n(This document autogenerated on %s)\n',date);

% if not writing to the screen then close file
if( output_handle ~= 1)
  fclose(output_handle);
end
